"use strict";
const common_vendor = require("../../../common/vendor.js");
common_vendor.defineStore("app", {
  state: () => ({
    systemInfo: {}
  }),
  getters: {
    getSystemInfo() {
      return this.systemInfo;
    }
  },
  actions: {
    setSystemInfo(info) {
      this.systemInfo = info;
    },
    initSystemInfo() {
      common_vendor.index.getSystemInfo({
        success: (res) => {
          this.setSystemInfo(res);
        },
        fail: (err) => {
          console.error(err);
        }
      });
    },
    checkUpdate() {
      const updateManager = common_vendor.index.getUpdateManager();
      updateManager.onCheckForUpdate((res) => {
        console.log(res.hasUpdate);
      });
      updateManager.onUpdateReady(() => {
        common_vendor.index.showModal({
          title: "更新提示",
          content: "新版本已经准备好，是否重启应用?",
          success(res) {
            if (res.confirm) {
              updateManager.applyUpdate();
            }
          }
        });
      });
      updateManager.onUpdateFailed((res) => {
        console.error(res);
        common_vendor.index.showToast({
          title: "更新失败",
          icon: "error"
        });
      });
    }
  }
});
